package com.hy.erp.inventory.service;

import java.util.List ;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

/*import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
import org.jboss.seam.async.Schedule ;
*/
import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.UnitsDao;
import com.hy.erp.inventory.dao.interfaces.IUnitConversionRateDao;
import com.hy.erp.inventory.dao.interfaces.IUnitsDao;
import com.hy.erp.inventory.dao.interfaces.IUserDao;
import com.hy.erp.inventory.pojo.UnitType;
import com.hy.erp.inventory.pojo.Units;
import com.hy.erp.inventory.pojo.interfaces.IUnitConversionRate;
import com.hy.erp.inventory.pojo.interfaces.IUnits;
import com.hy.erp.inventory.pojo.interfaces.IUser;
import com.hy.erp.inventory.service.interfaces.IUnitsService;
//import com.hy.erp.inventory.vsoft.libra.enterprise.framework.persistence.entity.AbstractPersistentEntity;
/**
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-10-12；时间：上午10:58:26</li>
 * <li>字段类型：long；字段名称：serialVersionUID</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
/*@Name("unitsService")
@ Scope ( ScopeType.STATELESS )
@ Stateless*/
@Component("unitsService")
public class UnitsService
							extends
							AbstractBusinessService < UnitsDao >
																	implements
																	IUnitsService
{

	
	private static final long	serialVersionUID	=
														- 5468483670098445675L ;
	
	private IUnitsDao unitsDao=null;

	@Resource(name="unitsDao")
	public void setCargoSpaceTypeDao(IUnitsDao unitsDao) {
		this.unitsDao = unitsDao;
	}

	/**
	 * 
	 * 构造函数
	 */
	public UnitsService()
	{
		super ( );
	}

	@ Override
	public String[] addUnits (
								Units[] units )
	{
		if(units==null)
		{
			return null;
		}
		else
		{
		//	IUnitsDao dao=( IUnitsDao ) this.getDao ( IUnits.class );
//			IUnits iUnits=units;
			return unitsDao.persist ( units ) ;
		}
	}

	@ Override
	public Integer removeUnits (
									String [ ] unitsIds )
	{
		if ( ( null == unitsIds )
			     || ( unitsIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{
			//	IUnitsDao dao=( IUnitsDao ) this.getDao ( IUnits.class );
				return unitsDao.remove ( unitsIds );
			}
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public boolean modifyUnits (
									Units units )
	{
		if ( ( null == units ) || ( null == units.getIdentifier ( ) ))
		{
			return true;
		}
		else
		{
	//		IUnitsDao dao=( IUnitsDao ) this.getDao ( IUnits.class );
		//	IUnits iUnits=units;
			
			if ( null == units )
			{
				throw new ArchitectureFoundationException (
				                                            "修改用户实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			return (unitsDao.merge ( units )!=null) ;
		}
		
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public List < Units > getUnitsById (
											String [ ] Id )
	{
		if((Id.length!=0)||(Id!=null))
		{
		//	IUnitsDao dao=( IUnitsDao ) this.getDao ( IUnits.class );
			return unitsDao.findByIdentifier ( Id );
		}
		return null ;
	}

	@ Override
	public String [ ] addUnits (
									Object [ ] objects )
	{
//		IUnitsDao dao=( IUnitsDao ) this.getDao ( IUnits.class );
		Units[] units=new Units[objects.length];
		for ( int i =
						0 ; i < objects.length ; i ++ )
		{
			Units units2=( Units ) objects[i];
			units[i]=units2;
		}
		return unitsDao.persist ( units ) ;
	}

	@ Override
	public List < Units > getAllUnits ( )
	{
	//	IUnitsDao dao=( IUnitsDao ) this.getDao ( IUnits.class );
		return unitsDao.find ( ) ;
	}

	@ Override
	public Units getUnitsById (
									String id )
	{


		if (  null == id )
			{
				return null ;
			}
			else
			{
			//	IUnitsDao dao=( IUnitsDao ) this.getDao ( IUnits.class );
				return unitsDao.findByIdentifier ( id );
				
			}
	
	
	}

	

	@ Override
	public String [ ] modifyUnits (
									Object [ ] objects )
	{
		if (  null == objects ) 
		{
			return null;
		}
		else
		{
	//		IUnitsDao dao=( IUnitsDao ) this.getDao ( IUnits.class );
			Units[] units=new Units[objects.length];
            for(int i=0;i<objects.length;i++)
            {
            	Units units2=( Units ) objects[i];
            	units[i]=units2;
            }
			
			return unitsDao.merge ( units );
		}
	}

}
